// pipe_wrapper.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "pipe_wrapper.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


#include "redir.h"
#include "H264_mencoder.h"
/*
 *	Global variable defined here
 */
#define TXT_MENCODER_PATH "G:\\mywork\\mplayer-compiler\\bin_release\\"
#define TXT_MENCODER_EXT  "mencoder.exe "

/************************************************************************/
/* test program                                                                     */
/************************************************************************/
#if 0

// The one and only application object

CWinApp theApp;

using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
	}




	CRedir *redir_class = new CRedir;

	CString str_enc;

#if 1 //  [11/1/2008]
	//mencoder invoke
	str_enc = TXT_MENCODER_PATH;
	str_enc += TXT_MENCODER_EXT;
	str_enc += "G:\\konka_stream\\h264-(mp4)\\ntu.mp4  ";
	str_enc += "-ovc copy -oac copy -of avi -o aa.avi";
#else 
	//get file information
	str_enc	= TXT_MENCODER_PATH;
	str_enc += "mplayer.exe ";
	str_enc += "-vo null -ao null -frames 0 -identify G:\\mywork\\mplayer-compiler\\bin_release\\test.wmv";
	
	CFileInfoRedir FileInfo;
	FileInfo.StartChildProcess(str_enc, TRUE);
	while (FileInfo.IsChildRunning()) {
		Sleep(100);
	};
	{
		FileInfo.Format_msg();	
	}
	
#endif


	//////////////////////////////////////////////////////////////////////////
	CH264_mencoder h264_mencoder;
	CAC3_mencoder ac3_mencoder;
	const char *str_h264 = h264_mencoder.get_mencoder_opts();
	char *str_ac3 = ac3_mencoder.get_ac3_2channel_opts();
	//////////////////////////////////////////////////////////////////////////
	



//	PROCESS_INFORMATION pro_info;
	redir_class->StartChildProcess(str_enc, TRUE);

	while (redir_class->IsChildRunning()) {
		static int ref = 0;

		ref ++;
		Sleep(100);
		if (ref == 100) {
			redir_class->SuspendChildProcess();
			printf("suspend child precess mencoder \n");
		}
		if (ref == 120) {
			redir_class->ResumeChildProcess();
			printf("resume child process mencoder\n");
		}
		if (ref == 130) {
			redir_class->TerminateChildProcess();
			printf("terminate child process\n");
			ref = 0;
//			break;
		}
	}



	delete redir_class;
	redir_class = NULL;

	return nRetCode;
}
#endif